1 using System.Collections;
2 using
System.Collections.Generic;
3 using
UnityEngine;
4
5 public
class ZoomCamera : MonoBehaviour, IInputReceiver {
6
7     
[SerializeField]
8     
private int sensitivity = 5;
9     
[SerializeField]
10     
private int minFOV = 20;
11     
[SerializeField]
12     
private int maxFOV = 80;
13
14     
private Camera zoomCamera;
15     
private float fieldOfView;
16
17     
// Use this for initialization
18     
void Start() {
19         zoomCamera = Camera.main;
20         fieldOfView = zoomCamera.fieldOfView;
21         EnableInput();
22     }
23
24     
public void EnableInput() {
25         InputManager.InputEvent += OnInputEvent;
26     }
27
28     
public void DisableInput() {
29         InputManager.InputEvent -= OnInputEvent;
30     }
31
32     
void OnDisable() {
33         DisableInput();
34     }
35
36     
public void OnInputEvent(InputActionType action) {
37         
switch (action) {
38             
case InputActionType.ZOOM_IN:
39                 fieldOfView -= sensitivity;
40                 
break;
41             
case InputActionType.ZOOM_OUT:
42                 fieldOfView += sensitivity;
43                 
break;
44         }
45
46         fieldOfView = Mathf.Clamp(fieldOfView,minFOV,maxFOV);
47         zoomCamera.fieldOfView = fieldOfView;
48     }
49 }


Use this for initialization



Gõ tìm kiếm nhanh...